﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.Authorization;
using Core.Toolkit.Authorization.Help;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
#pragma warning disable CS1591
namespace Core.SimpleTemp.Mvc.Api.Internal
{
    public class CoreApiController : ControllerBase
    {
        /// <summary>
        /// 根据functionCodes 查询是否有对应权限
        /// </summary>
        /// <param name="functionCodes"></param>
        /// <returns></returns>
        protected async Task<List<KeyValue<string, bool>>> AuthorizeListAsync(string[] functionCodes)
        {

            var authorizationService = (IAuthorizationService)HttpContext.RequestServices.GetService(typeof(IAuthorizationService));
            var list = await authorizationService.AuthorizeListAsync(functionCodes, User);
            return list;
        }

        /// <summary>
        /// 获取当前控制器下权限Code
        /// </summary>
        /// <returns></returns>

        protected string[] GetFunctionCodes()
        {
            PermissionHelp permissionHelp = new PermissionHelp(this);
            return permissionHelp.GetFunctionCode().ToArray();
        }

        /// <summary>
        /// 当前用户信息
        /// </summary>
        protected UserIdentity UserIdentity
        {
            get
            {
                return HttpContext?.User?.GetUserIdentity();
            }
        }

        protected const string NULL_DATA_FOR_EXCEL_EXPORT = "无可用的数据供Excel导出";
    }


}
